package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 参考答案实体类
 * 对应数据库表：reference_answer
 *
 * 根据B-02-03-07简答题管理子模块设计文档实现
 * 管理简答题的参考答案信息，支持多版本答案、标准答案解析和智能匹配功能。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "reference_answer")

@Comment("参考答案表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReferenceAnswer {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 参考答案唯一标识符
     */
    @NotBlank(message = "参考答案ID不能为空")
    @Size(max = 50, message = "参考答案ID长度不能超过50个字符")
    @Column(name = "answer_id", nullable = false, length = 50, unique = true)
    private String answerId;

    /**
     * 关联的简答题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 参考答案代码
     */
    @NotBlank(message = "参考答案代码不能为空")
    @Size(max = 32, message = "参考答案代码长度不能超过32个字符")
    @Column(name = "answer_code", nullable = false, length = 32)
    private String answerCode;

    /**
     * 参考答案标题
     */
    @Size(max = 200, message = "参考答案标题长度不能超过200个字符")
    @Column(name = "answer_title", length = 200)
    private String answerTitle;

    /**
     * 参考答案内容
     */
    @NotBlank(message = "参考答案内容不能为空")
    @Column(name = "answer_content", nullable = false, columnDefinition = "TEXT")
    private String answerContent;

    /**
     * 答案类型（STANDARD-标准答案，MODEL-模范答案，SAMPLE-示例答案，ALTERNATIVE-替代答案）
     */
    @NotBlank(message = "答案类型不能为空")
    @Size(max = 20, message = "答案类型长度不能超过20个字符")
    @Column(name = "answer_type", nullable = false, length = 20)
    private String answerType;

    /**
     * 答案分类（FULL-完整答案，PARTIAL-部分答案，KEY-要点答案，DETAILED-详细答案）
     */
    @Size(max = 20, message = "答案分类长度不能超过20个字符")
    @Column(name = "answer_category", length = 20)
    private String answerCategory;

    /**
     * 答案详细解析
     */
    @Column(name = "answer_explanation", columnDefinition = "TEXT")
    private String answerExplanation;

    /**
     * 答案要点分析
     */
    @Column(name = "key_points_analysis", columnDefinition = "TEXT")
    private String keyPointsAnalysis;

    /**
     * 关键知识点
     */
    @Column(name = "key_knowledge_points", columnDefinition = "TEXT")
    private String keyKnowledgePoints;

    /**
     * 答案评分标准
     */
    @Column(name = "scoring_standard", columnDefinition = "TEXT")
    private String scoringStandard;

    /**
     * 预期得分
     */
    @Column(name = "expected_score", precision = 5, scale = 2)
    private BigDecimal expectedScore;

    /**
     * 答案质量评分（0-100分）
     */
    @Column(name = "quality_score", precision = 5, scale = 2)
    private BigDecimal qualityScore;

    /**
     * 答案复杂度级别
     */
    @Column(name = "complexity_level")
    private Integer complexityLevel;

    /**
     * 是否为标准答案
     */
    @NotNull(message = "标准答案标识不能为空")
    @Column(name = "is_standard", nullable = false)
    private Boolean isStandard;

    /**
     * 是否为推荐答案
     */
    @NotNull(message = "推荐答案标识不能为空")
    @Column(name = "is_recommended", nullable = false)
    private Boolean isRecommended;

    /**
     * 是否启用智能匹配
     */
    @NotNull(message = "智能匹配设置不能为空")
    @Column(name = "enable_smart_matching", nullable = false)
    private Boolean enableSmartMatching;

    /**
     * 匹配算法类型（EXACT-精确匹配，FUZZY-模糊匹配，SEMANTIC-语义匹配，HYBRID-混合匹配）
     */
    @Size(max = 20, message = "匹配算法类型长度不能超过20个字符")
    @Column(name = "matching_algorithm", length = 20)
    private String matchingAlgorithm;

    /**
     * 匹配阈值
     */
    @Column(name = "matching_threshold", precision = 3, scale = 2)
    private BigDecimal matchingThreshold;

    /**
     * 关键词权重配置（JSON格式）
     */
    @Column(name = "keyword_weights", columnDefinition = "TEXT")
    private String keywordWeights;

    /**
     * 同义词配置（JSON格式）
     */
    @Column(name = "synonyms_config", columnDefinition = "TEXT")
    private String synonymsConfig;

    /**
     * 答案长度配置
     */
    @Size(max = 100, message = "答案长度配置长度不能超过100个字符")
    @Column(name = "length_config", length = 100)
    private String lengthConfig;

    /**
     * 答案结构要求
     */
    @Column(name = "structure_requirements", columnDefinition = "TEXT")
    private String structureRequirements;

    /**
     * 语言风格要求
     */
    @Size(max = 100, message = "语言风格要求长度不能超过100个字符")
    @Column(name = "style_requirements", length = 100)
    private String styleRequirements;

    /**
     * 评分点关联（JSON格式）
     */
    @Column(name = "scoring_points_mapping", columnDefinition = "TEXT")
    private String scoringPointsMapping;

    /**
     * 答案变体（多个可能答案，JSON格式）
     */
    @Column(name = "answer_variants", columnDefinition = "TEXT")
    private String answerVariants;

    /**
     * 常见错误对比
     */
    @Column(name = "common_errors_comparison", columnDefinition = "TEXT")
    private String commonErrorsComparison;

    /**
     * 答案使用说明
     */
    @Column(name = "usage_instructions", columnDefinition = "TEXT")
    private String usageInstructions;

    /**
     * 答案版本号
     */
    @NotNull(message = "答案版本号不能为空")
    @Column(name = "answer_version", nullable = false)
    private Integer answerVersion;

    /**
     * 上一个版本ID（用于版本管理）
     */
    @Size(max = 50, message = "上一版本ID长度不能超过50个字符")
    @Column(name = "previous_version_id", length = 50)
    private String previousVersionId;

    /**
     * 版本变更说明
     */
    @Column(name = "version_changes", columnDefinition = "TEXT")
    private String versionChanges;

    /**
     * 参考答案状态（ACTIVE-激活，INACTIVE-非激活，DEPRECATED-已废弃，DRAFT-草稿）
     */
    @NotBlank(message = "参考答案状态不能为空")
    @Size(max = 20, message = "参考答案状态长度不能超过20个字符")
    @Column(name = "answer_status", nullable = false, length = 20)
    private String answerStatus;

    /**
     * 是否激活
     */
    @NotNull(message = "激活状态不能为空")
    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    /**
     * 适用难度级别
     */
    @Size(max = 50, message = "适用难度级别长度不能超过50个字符")
    @Column(name = "applicable_difficulty", length = 50)
    private String applicableDifficulty;

    /**
     * 适用评分模式
     */
    @Size(max = 50, message = "适用评分模式长度不能超过50个字符")
    @Column(name = "applicable_grading_mode", length = 50)
    private String applicableGradingMode;

    /**
     * 答案创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 审核者ID
     */
    @Size(max = 50, message = "审核者ID长度不能超过50个字符")
    @Column(name = "reviewed_by", length = 50)
    private String reviewedBy;

    /**
     * 发布者ID
     */
    @Size(max = 50, message = "发布者ID长度不能超过50个字符")
    @Column(name = "published_by", length = 50)
    private String publishedBy;
}